﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using UI.ParentForm;
using Components;

namespace UI.ConstSet
{
    public partial class FrmBas0a01Medit : UI.ParentForm.BaseMedit
    {
        public FrmBas0a01Medit(string modulecode, string action, string text, string key)
            : base(modulecode, action)
        {
            InitializeComponent();

            this.Text = text;
            this.Key = key;

            //回写的方法
            this.SaveCallFuntion = "Bas0a01Manager$SaveData"; //保存的方法
            IsAfterSaveCloseWin = false;
            this.allowDtlEmpty = false; //可能用户一次想把全部的记录删除
            this.MaxStateFlag = true;
            if (!string.IsNullOrEmpty(this.Key))
            {
                LoadData();
                IsAfterSaveCloseWin = true;
            }
        }


        //加载修改数据
        private void LoadData()
        {
            base.LoadEditData(null, string.Format(" groupcode ='{0}' ", this.Key));
            base.LoadDtlData(null, string.Format(" groupcode ='{0}' ", this.Key));
        }

        protected override bool Check()
        {
            if ("A" == this.Action)
            {
                string cntcode = Components.Validation.ToString(this.tbSummary.GetValue("groupcode")); //合同代码
                //由于合同代码可以不填写，在不填写的时候不验证合同号的存在性
                if (string.IsNullOrEmpty(cntcode)) return true;

                System.Collections.Hashtable hs = new System.Collections.Hashtable();
                hs["groupcode"] = cntcode;
                bool reflt = UI.Lib.Factory.CommonHelper.Entity.DataInData("Bas0a01", hs);
                if (reflt)
                {
                    MessageBox.Show("当前组别代码已经存在！", "提示");
                    this.tbSummary.Focus("groupcode");
                    return false;
                }

                return true;
            }

            return true;
        }

        protected override void AfterDtlValueChanged(string name, object value)
        {
            if ("valuecode" == name)
            {
                string groupcode = Validation.ToString(this.tbSummary.GetValue("groupcode"));
                this.dgvDtl.SetValue("listid", string.Concat(groupcode, value)); //设置主键
            }
        }
    }
}
